package app.pages;

import java.io.File;

import org.springframework.beans.factory.annotation.Configurable;
import org.vaadin.navigator7.NavigableApplication;
import org.vaadin.navigator7.Page;

import app.downloadupload.DownloadResource;
import app.webapplication.MyApplication;

import com.vaadin.Application;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.VerticalLayout;

/** 
 * 
 * @author Faton Alia
 * @author David Gianorio
 * @author Nachman Mathieu
 * 
 * This class contains will be used to download Application in the server */

@Page
@Configurable(preConstruction = true)
public class DownloadPage extends VerticalLayout implements ClickListener{

	public DownloadPage(){
		Button but = new Button();
		but.addListener(this);
		addComponent(but);
	}

	public void buttonClick(ClickEvent event) {

		Application myApp = (MyApplication)NavigableApplication.getCurrent();

		File file = new File("eclipse.exe");
		System.out.println(file.getAbsolutePath());

		try {
			DownloadResource downloadResource = new DownloadResource(file, myApp);
			myApp.getMainWindow().open(downloadResource, "_new");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}